layui.use(['upload','layer'], function(){
    var upload = layui.upload
        ,layer = parent.layer === undefined ? layui.layer : top.layer
        ,$ = layui.jquery;
    var u = navigator.userAgent, app = navigator.appVersion;
    var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1; //android终端或者uc浏览器
    if(isAndroid){
        $(".choicePhoto").attr('capture','camera');
    }
    var loadUpload;
    //执行实例
    upload.render({
        elem: '.choicePhoto'
        //,url: '/stuPhotoDr'
        ,url: '/stuOriginalPhotoDr'
        //,data: {} //可选项。额外的参数，如：{id: 123, abc: 'xxx'}
        //,exts:'jpg|jpeg|bmp|png'
        ,accept: 'images' //允许上传的文件类型
        ,acceptMime: 'image/jpg, image/jpeg, image/png' //'image/*'
        ,multiple: false
        ,size: 15360 //最大允许上传的文件大小
        ,before: function(){
            loadUpload = layer.load(3,{
                shade:0.3
            });
            //var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
        }
        ,done: function(res,index,upload){
            layer.close(loadUpload);
            //console.log(res);
            //console.log(res.msg);
            if('success' == res.msg){
                layer.msg("导入成功。");
                //location.href = "/toPhotoMake";
                location.href = "/toPhotoCheck";
            }else if('error' == res.msg){
                layer.msg("导入失败。");
            }else{
                layer.msg(res.msg);
            }
        }
        ,error: function(){
            layer.msg("文件上传失败");
        }
    });

    /*$('.choicePhoto').click(function () {
        alert('123');
        $('input[type=file]').attr('capture','camera');
    });*/

    $(".leftNav").click(function(){
        location.href="/index";
    });

    //PhotoMake
    $(".reset-photo").click(function(){
        location.href="/resetPhoto";
    });

    $(".check-photo").click(function(){
        /*loadUpload = layer.load(3,{
            shade:0.3
        });*/
        $.ajax({
            async: false,
            type: "POST",
            url: "/transformOriginal",
            data: "address="+$("#address").val(),
            before: function(){
                loadUpload = layer.load(3,{
                    shade:0.3
                });
            },
            success: function(data) {
                layer.close(loadUpload);
                console.log(data);
                if('success' == data){
                    layer.msg("转化成功。");
                    location.href="/toPhotoMake";
                }else if('error' == data){
                    layer.msg("转化失败。");
                }else{
                    layer.msg(data);
                }
            },
            error:function(XMLHttpRequest, textStatus){
                console.log(XMLHttpRequest);
                console.log(textStatus);
                layer.msg("保存失败，请联系管理员。");
            }
        });
    });

    $(".admit-photo").click(function(){
        $.ajax({
            async: false,
            type: "POST",
            url: "/admitTempPhoto",
            data: "address="+$("#address").val(),
            before: function(){
                loadUpload = layer.load(1,{
                    shade:0.01
                });
            },
            success: function(data) {
                layer.close(loadUpload);
                if('success' == data){
                    layer.msg("导入成功。");
                    location.href="/index";
                }else if('error' == data){
                    layer.msg("导入失败。");
                }else{
                    layer.msg(data);
                }
            },
            error:function(XMLHttpRequest, textStatus){
                console.log(XMLHttpRequest);
                console.log(textStatus);
                layer.msg("保存失败，请联系管理员。");
            }
        });
    });
});